<template>
  <div>
   <el-select v-model="value" placeholder="请选择" style="width: 120px">
     <el-option
       v-for="item in options"
       :key="item.administrativeCode"
       :label="item.administrativeName"
       :value="item.administrativeCode"
     ></el-option>
   </el-select>
  </div>
</template>
<script lang="ts" setup>
import { defineEmits, ref, watch } from "vue";
import { Input, Form } from "ant-design-vue";
import { getInfoById } from "@/api/system/user";
import useUserStore from '@/store/modules/user'
const userStore = useUserStore()
const formItemContext = Form.useInjectFormItemContext();
const emits = defineEmits(["update:modelValue", "change", "blur"]);
const options = ref([]);
const props = defineProps({
  componentSchema: {
    default: () => ({}),
    type: Object,
  },
  modelValue: {
    default: () => "",
    type: String,
  },
});
const value = ref("");
// 读卡完成后
getInfoById(userStore.id).then(response => {
  options.value=[]
  if(props.componentSchema.adminLevel=="villageList"){
    //社区
    options.value = response.villageList
  }else if(props.componentSchema.adminLevel=="communityList"){
    //小区
    options.value = response.communityList
  }else if(props.componentSchema.adminLevel=="townList"){
    //街道
    options.value = response.townList
  }else {
    options.value = response.villageList
  }

  console.info("🚀 ~ file:index method: line:37 -----",options.value  )
})

watch(value, (e) => {
  emits("update:modelValue", e);
  // 触发校验的change事件
  formItemContext.onFieldChange();
});
watch(
    () => props.modelValue,
    (e) => {
      if (e && e.length > 0) {
        value.value = e;
      }
    },
    { immediate: true }
);
</script>
